<template>
	<u-navbar
		class="navbar" 
		:back-icon-size="36" 
		:back-icon-name="backIcon" 
		:back-icon-color="backColor" 
		back-text="" 
		:title="title" 
		:title-color="titleColor" 
		:border-bottom="borderBottom" 
		:title-bold="false" 
		v-bind="$attrs" 
		v-on="$listeners"
		:custom-back="back"
		backgroundColor
		:background="backgroundObj"
		:isBack="isBack"
		titleWidth='540'
	>
		<slot name="center"></slot>
		<slot name="right"></slot>
	</u-navbar>
	<!-- #ifdef H5 -->
	<!-- #endif -->
</template>

<script>
	export default {
		inheritAttrs: false,
		props: {
			title: {
				type: String,
				default: ''
			},
			titleColor: {
				type: String,
				default: '#17273a'
			},
			titleSize: {
				type: [String, Number],
				default: 32
			},
			backIcon: {
				type: String,
				// default: 'arrow-leftward'
				default: 'arrow-left'
			},
			backColor: {
				type: String,
				default: '#919191'
			},
			isBack: {
				type: Boolean,
				default: true
			},
			background: {
				type: String,
				default: 'transparent'
			},
			isComfirm: {
				type: Boolean,
				default: false
			},
			borderBottom: {
				type: Boolean,
				default: false
			}
		},
		computed: {
			backgroundObj () {
				if (this.background == 'transparent') {
					return {
						background: 'rgba(0,0,0,0)'
					}
				} else {
					return {
						background: this.background
					}
				}
				
			}
		},
		data() {
			return {
			}
		},
		methods: {
			back() {
				// console.log(getCurrentPages());
				if (this.isComfirm) {
					this.$emit('beforeBack')
				} else {
					// #ifdef H5
					let pages = getCurrentPages()
					if(pages.length == 1) {
						uni.navigateTo({
							url: '/pages/home/home'
						})
					} else {
						uni.navigateBack({})
					}
					// #endif
					
					// #ifndef H5
					// uni.navigateBack({})
					let pages = getCurrentPages()
					console.log(pages);
					if(pages.length == 1) {
						uni.navigateTo({
							url: '/pages/home/home'
						})
					} else {
						uni.navigateBack({})
					}
					// #endif
				}
			}
		}
	}
</script>

<style>

</style>
